package kxfang.com.common.constant;

import kxfang.com.common.parameter.TokenModel;
import kxfang.com.common.utils.Md5Util;
import kxfang.com.common.utils.StringUtils;

public class Constant {

    //图片地址
    public static String PHOTO_SERVER_URL = "";
    // 服务器接口地址
    public static String API_SERVER_URL = "";
    // 网页加载
    public static String LOAD_WEBVIEWURL = "";
    //支付地址
    public static String PAY_URL = "";
    //融云
    public static String IM_URL = "";
    //融云appkey
    public static String RY_APP_KEY = "";

    public static void init(String ServerUrl) {
        switch (ServerUrl) {
            case "Release":
                //正式服务器地址
                API_SERVER_URL = "https://appapi.kxfang.com";
                PHOTO_SERVER_URL = "https://img.kxfang.com/";
                LOAD_WEBVIEWURL = "https://m.kxfang.com";
                RY_APP_KEY = "6tnym1br6prz7";
                PAY_URL = "https://payapi.kxfang.com";
                IM_URL = "https://tool.kxfang.com/";
                break;
            case "Test":
                // 测试服务器
                API_SERVER_URL = "https://testapi.kxfang.com";
                PAY_URL = "https://testpay.kxfang.com";
                LOAD_WEBVIEWURL = "https://testm.kxfang.com";
                PHOTO_SERVER_URL = "https://img.kxfang.com/";
                RY_APP_KEY = "6tnym1br6prz7";
                IM_URL = "https://testtool.kxfang.com";
                break;
            case "Debug":
                // 开发服务器地址
                PHOTO_SERVER_URL = "http://192.168.1.168:1071";
                API_SERVER_URL = "http://192.168.1.168:1070";
//                LOAD_WEBVIEWURL = "http://192.168.0.123:8081";
                LOAD_WEBVIEWURL = "http://192.168.1.165:8081/static/";
                RY_APP_KEY = "c9kqb3rdc4dij";
                PAY_URL = "http://192.168.1.168:9000";
                IM_URL = "http://192.168.1.168:1075";
                break;
        }
    }
    public static String yqID = "";

    public static final String TOKEN_IDENTIF = "kxfang.com";

    public static final String TOKEN_NONCE = "OY8OVCC1TzEZM2SuEDYRuUUYUhrbflsR";

    //用户id
    public static final String HAWK_USER_INFO = "user_info_id";
    //融云token
    public static final String IM_TOKEN_SP = "im_token";
    //融云ID
    public static final String IM_UESR_ID = "im_id";
    public static boolean ISIM_CODE = true;
    //微信appId
    public static final String WX_APP_ID = "wxf1d8a99366194847";
    // 微信appKey
    public static final String WX_APP_KEY = "ad311c79632b7524bfbef14e67efee75";
    //小程序原始ID
    public static final String WX_MIN_ID = "gh_806ac8ace14b";
    //二维码code值
    public static final int REQUEST_CODE = 111;


    //0=全部 1= 商家(11=美食 12=店铺/便利店) 2= 商品 4=工作 5=招聘公司 3= 房源（ 30 出租 31 出售 32 租售）
    public static final int SEARCH_ALL = 0;

    public static final int SEARCH_XXWL = 60;

    public static final int SEARCH_FX = 24;

    public static final int SEARCH_OLD_CAR = 20;

    public static final int SEARCH_OLD_GOODS = 21;

    public static final int SEARCH_DIS_STORE = 22;

    public static final int SEARCH_DIS_BUY = 23;

    public static final int SEARCH_SHOP = 1;

    public static final int SEARCH_FOOD = 11;

    public static final int SEARCH_SHOP_CS = 12;

    public static final int SEARCH_GOODS = 2;

    public static final int SEARCH_JOB = 4;

    public static final int SEARCH_COMPANY = 5;

    public static final int SEARCH_HOUSE = 3;

    public static final int SEARCH_CZ = 30;

    public static final int SEARCH_SOUL = 31;

    public static final int SEARCH_ZS = 32;

    public static final int SEARCH_JJR = 33;

    public final static int TASK_TYPE_CONNECT = 1;

    public final static int TASK_TYPE_PRINT = 2;

    /**
     * 支付相关
     */
    public static final class PayConstants {
        // 微信支付
        public static final int WX_PAY = 1;
        // 支付宝支付
        public static final int ALI_PAY = 2;

        // 支付宝回调
        public static final int SDK_PAY_FLAG = 1;
    }

    /**
     * 订单中退款原因中字符串的分割标准
     */
    public static final String SPLIT = "${refundvalue}";
    /**
     * 酒店预订
     */
    public static final String HOTEL_WEB_BOOK = "https://m.ly.com/hotel/";
    /**
     * 机票预订
     */
    public static final String PLANT_WEB_BOOK = "https://m.ly.com/kylintouch/cindex";
    /**
     * 火车票预订
     */
    public static final String TRAIN_WEB_BOOK = "https://m.ly.com/universal/touch/?refid=10758821#/index";
    /**
     * 汽车票预订
     */
    public static final String BUS_WEB_BOOK = "https://m.ly.com/bus/#/";

    /**
     * token
     *
     * @return
     */
    public static TokenModel model() {
        String timestamp = System.currentTimeMillis() / 1000 + "";
        String identif = Constant.TOKEN_IDENTIF;
        String nonce = Constant.TOKEN_NONCE;
        String token = getToken(timestamp);
        TokenModel tokenModel = new TokenModel();
        tokenModel.setTimestamp(timestamp);
        tokenModel.setIdentif(identif);
        tokenModel.setNonce(nonce);
        tokenModel.setToken(token);
        return tokenModel;
    }

    private static String getToken(String time) {
        String[] a = {time, Constant.TOKEN_IDENTIF, Constant.TOKEN_NONCE};
        String newStr = StringUtils.join(a, "&");
        String code = Md5Util.md5Decode(newStr);
        String token = Md5Util.md5Decode(code);
        return token;
    }
}
